﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using RbacPermissionManage.Application;
using RbacPermissionManage.Application.Menus;
using RbacPermissionManage.Application.Menus.Dto;

namespace RbacPermissionManage.WebAPI.Controllers
{
    /// <summary>
    /// 菜单管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MenuController : ControllerBase
    {
        private readonly IMenuServices menuServices;

        public MenuController(IMenuServices menuServices)
        {
            this.menuServices = menuServices;
        }

        /// <summary>
        /// 添加菜单
        /// </summary>
        /// <param name="createDto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> CreateAsync(MenuCreateDto createDto)
        {
            return Ok(await menuServices.CreateAsync(createDto));
        }

        /// <summary>
        /// 获取结点信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetNodesAsync([FromQuery]SearchDto searchDto)
        {
            var list = await menuServices.GetNodesAsync(searchDto);
            return Ok(list);
        }

        /// <summary>
        /// 根据Id获取adminDto
        /// </summary>
        /// <param name="MenuId">管理员Id</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> BackfillAsync(int MenuId)
        {
            return Ok(await menuServices.BackfillAsync(MenuId));
        }

        /// <summary>
        /// 修改菜单
        /// </summary>
        /// <param name="updateDto"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<IActionResult> UpdateAsync(MenuUpdateDto updateDto)
        {
            return Ok(await menuServices.UpdateAsync(updateDto));
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="MenuId"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> DeleteAsync(int MenuId)
        {
            return Ok(await menuServices.DeleteAsync(MenuId));
        }

        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="menuIds"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> BatchDelAsync(List<int> menuIds)
        {
            return Ok(await menuServices.BatchDelAsync(menuIds));
        }
    }
}
